<template>
  <div>
    <el-form label-width="160px"  v-loading="loading">
    
        <el-form-item label="微信小程序app_id">
            <el-input v-model="formData.wechat_mini_app_id"></el-input>
        </el-form-item>
        <el-form-item label="微信小程序secret">
            <el-input v-model="formData.wechat_mini_secret"></el-input>
        </el-form-item>
      
    </el-form>
    <div class="flex flex-start " style="margin-left:160px;">
      <el-button type="primary" @click="save()" :loading="saveLoading" >保存</el-button>
    </div>
    
  </div>
</template>

<script setup>
import { defineComponent, onMounted, getCurrentInstance, ref } from "vue";
import { getToken } from '@/utils/sys';
const {
  appContext: {
    config: { globalProperties },
  },
} = getCurrentInstance();

const { $storage, $http, $ekMessage, $ekMessageBox,$imageBaseUrl  } = globalProperties;

const saveLoading = ref(false);
const formData = ref({
  wechat_mini_app_id: "",
  wechat_mini_secret: "",
});
const loading = ref(false)
const init = () => {
  loading.value = true;
  $http
    .get(`business/config/getConfigByGroup?authCode=FUNCTION_CONFIG_WECHAT`,{ params:{code:'CONFIG_GROUP_WECHAT_MINI'}})
    .then((res) => {
      if (res.status === "success") {
       
        if(res.data.list?.length){
            for(let item of res.data.list){
                formData.value[item.config_key] =  item.config_value;
            }
        }
        loading.value = false;
      }
    });
};
const save = () => {
  $http
    .post(`business/config/save?authCode=FUNCTION_CONFIG_WECHAT&code=CONFIG_GROUP_WECHAT_MINI`, {
      ...formData.value,
    })
    .then((res) => {
        if(res.status =='success'){
          $ekMessage.success('操作成功');

        }
    });
};


onMounted(async () => {
  init();
});
</script>
